define(['jquery', 'bootstrap', 'backend', 'table', 'form'], function ($, undefined, Backend, Table, Form) {

    var Controller = {
        index: function () {
            // 初始化表格参数配置
            Table.api.init({
                extend: {
                    index_url: 'fedition_ordershopify_warehouse/index' + location.search,
                    add_url: 'fedition_ordershopify_warehouse/add',
                    edit_url: 'fedition_ordershopify_warehouse/edit',
                    del_url: 'fedition_ordershopify_warehouse/del',
                    multi_url: 'fedition_ordershopify_warehouse/multi',
                    import_url: 'fedition_ordershopify_warehouse/import',
                    table: 'fedition_ordershopify_warehouse',
                }
            });

            var table = $("#table");

            // 初始化表格
            table.bootstrapTable({
                url: $.fn.bootstrapTable.defaults.extend.index_url,
                pk: 'id',
                sortName: 'id',
                columns: [
                    [
                        {checkbox: true},
                        {field: 'id', title: __('Id'), operate: 'LIKE'},
                        {field: 'createtime', title: __('Createtime'), operate:'RANGE', addclass:'datetimerange', autocomplete:false, formatter: Table.api.formatter.datetime},
                        {field: 'updatetime', title: __('Updatetime'), operate:'RANGE', addclass:'datetimerange', autocomplete:false, formatter: Table.api.formatter.datetime},
                        {field: 'status', title: __('Status'), searchList: {"normal":__('Normal'),"hidden":__('Hidden')}, formatter: Table.api.formatter.status},
                        {field: 'name', title: __('Name'), operate: 'LIKE'},
                        {field: 'number', title: __('Number'), operate: 'LIKE'},
                        {field: 'order_number', title: __('Order_number'), operate: 'LIKE'},
                        {field: 'created_at', title: __('Created_at')},
                        {field: 'updated_at', title: __('Updated_at')},
                        {field: 'ytotal_price', title: __('Ytotal_price'), operate: 'LIKE'},
                        {field: 'total_price', title: __('Total_price'), operate: 'LIKE'},
                        {field: 'currency', title: __('Currency'), operate: 'LIKE'},
                        {field: 'financial_status', title: __('Financial_status'), operate: 'LIKE', formatter: Table.api.formatter.status},
                        {field: 'accounturl', title: __('Accounturl'), formatter: Table.api.formatter.url},
                        {field: 'ycreated_at', title: __('Ycreated_at'), operate: 'LIKE'},
                        {field: 'yupdated_at', title: __('Yupdated_at'), operate: 'LIKE'},
                        {field: 'gateway', title: __('Gateway'), operate: 'LIKE'},
                        {field: 'fulfillment_status', title: __('Fulfillment_status'), operate: 'LIKE', formatter: Table.api.formatter.status},
                        {field: 'countnum', title: __('Countnum')},
                        {field: 'freight', title: __('Freight'), operate:'BETWEEN'},
                        {field: 'freightmj', title: __('Freightmj'), operate:'BETWEEN'},
                        {field: 'material', title: __('Material'), operate:'BETWEEN'},
                        {field: 'istransfer', title: __('Istransfer')},
                        {field: 'transfertime', title: __('Transfertime'), operate: 'LIKE'},
                        {field: 'ismaterial', title: __('Ismaterial')},
                        {field: 'materialtime', title: __('Materialtime'), operate: 'LIKE'},
                        {field: 'isfiled', title: __('Isfiled')},
                        {field: 'filedtime', title: __('Filedtime'), operate: 'LIKE'},
                        {field: 'zcost', title: __('Zcost'), operate:'BETWEEN'},
                        {field: 'iszcost', title: __('Iszcost')},
                        {field: 'zcosttime', title: __('Zcosttime'), operate: 'LIKE'},
                        {field: 'gross_profit', title: __('Gross_profit'), operate:'BETWEEN'},
                        {field: 'updateordertime', title: __('Updateordertime'), operate: 'LIKE'},
                        {field: 'email', title: __('Email'), operate: 'LIKE'},
                        {field: 'shipping_name', title: __('Shipping_name'), operate: 'LIKE'},
                        {field: 'phone', title: __('Phone'), operate: 'LIKE'},
                        {field: 'city', title: __('City'), operate: 'LIKE'},
                        {field: 'address1', title: __('Address1'), operate: 'LIKE'},
                        {field: 'country_code', title: __('Country_code'), operate: 'LIKE'},
                        {field: 'customers_time', title: __('Customers_time'), operate: 'LIKE'},
                        {field: 'customers_status', title: __('Customers_status'), operate: 'LIKE', formatter: Table.api.formatter.status},
                        {field: 'customers_id', title: __('Customers_id'), operate: 'LIKE'},
                        {field: 'user_id', title: __('User_id'), operate: 'LIKE'},
                        {field: 'tracking_company', title: __('Tracking_company'), operate: 'LIKE'},
                        {field: 'tracking_number', title: __('Tracking_number'), operate: 'LIKE'},
                        {field: 'order_status_url', title: __('Order_status_url'), operate: 'LIKE', formatter: Table.api.formatter.url},
                        {field: 'tracking_status', title: __('Tracking_status'), searchList: {"rejection":__('Rejection'),"sign":__('Sign'),"way":__('Way'),"solicitation":__('Solicitation')}, formatter: Table.api.formatter.status},
                        {field: 'tracking_time', title: __('Tracking_time'), operate: 'LIKE'},
                        {field: 'updatemautictime', title: __('Updatemautictime'), operate: 'LIKE'},
                        {field: 'total_tip_received', title: __('Total_tip_received'), operate: 'LIKE'},
                        {field: 'province', title: __('Province'), operate: 'LIKE'},
                        {field: 'zip', title: __('Zip'), operate: 'LIKE'},
                        {field: 'operate', title: __('Operate'), table: table, events: Table.api.events.operate, formatter: Table.api.formatter.operate}
                    ]
                ]
            });

            // 为表格绑定事件
            Table.api.bindevent(table);
        },
        add: function () {
            Controller.api.bindevent();
        },
        edit: function () {
            Controller.api.bindevent();
        },
        api: {
            bindevent: function () {
                Form.api.bindevent($("form[role=form]"));
            }
        }
    };
    return Controller;
});